//package yb.ecp.fast.user.infra.datainit;
//
//import org.apache.commons.lang.ArrayUtils;
//import org.springframework.boot.CommandLineRunner;
//import org.springframework.jdbc.core.JdbcTemplate;
//import org.springframework.transaction.annotation.Transactional;
//import yb.ecp.fast.infra.infra.log.LogHelper;
//import yb.ecp.fast.infra.util.StringUtil;
//
///**
// * @author wanghao
// * @Description 运行数据库初始化脚本
// * @date 2018-02-28 16:57
// */
//public class DataRunner implements CommandLineRunner {
//    private final String[] ddlScript;
//
//    private final String[] dataScript;
//
//    private final JdbcTemplate jdbcTemplate;
//
//    public DataRunner(JdbcTemplate jdbcTemplate, String[] ddlScript, String[] dataScript) {
//        this.jdbcTemplate = jdbcTemplate;
//        this.ddlScript = ddlScript;
//        this.dataScript = dataScript;
//    }
//
//    @Override
//    @Transactional(rollbackFor = Exception.class)
//    public void run(String... args) throws Exception {
//        long timeBegin = System.currentTimeMillis();
//        LogHelper.monitor("======start running data init scripts======");
//        String[] scripts = (String[])ArrayUtils.addAll(ddlScript, dataScript);
//        runScript(scripts);
//        long spent = System.currentTimeMillis() - timeBegin;
//        LogHelper.monitor("======finish running data init scripts, spent: " + spent + "ms======");
//    }
//
//    private void runScript(String[] scripts) {
//        for (String script : scripts) {
//            if (!StringUtil.isNullOrSpace(script)) {
//                LogHelper.monitor("======execute script: " + script);
//                jdbcTemplate.execute(script);
//            }
//        }
//    }
//}
